<?php
/**
*作用:
*说明:
*版权:
*作者:Red	QQ:316765128
*时间:2011/7/28
**/
include_once './include/init.inc.php';

$goods_id = isset($_REQUEST['id'])  ? intval($_REQUEST['id']) : 0;

if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'like'){
	$sql = "select count(*) as num from " . $ecs->table('goods_like') ." where goods_id='".$goods_id."' and user_id='".$user_id."'";
	$like_num = $GLOBALS['db']->getOne($sql);
	if(empty($like_num)){
		$sql = "insert into " . $ecs->table('goods_like') ." set goods_id='".$goods_id."',user_id='".$user_id."'";
		$GLOBALS['db']->query($sql);
	}
}

/* 获得商品的信息 */
$goods = get_goods_info($goods_id,$db);
if ($goods === false){
	/* 如果没有找到任何记录则跳回到首页 */
	header("Location: ./\n");
	exit;
}else{
	$properties = get_goods_properties($goods_id,$db);  // 获得商品的规格和属性
	$smarty->assign('properties',          array_reverse($properties['pro']['商品属性']));       // 商品属性

	//red add
	$goods_desc = explode('||||',$goods['goods_desc']);
	if(!empty($goods_desc[0])){
		$goods['goods_desc'] = $goods_desc[0];
	}else{
		$goods['goods_desc'] = '';
	}
	if(!empty($goods_desc[1])){
		$goods['goods_info'] = $goods_desc[1];
	}else{
		$goods['goods_info'] = '';
	}
	
	//red end
	$smarty->assign('goods',              $goods);
	$smarty->assign('goods_id',           $goods['goods_id']);

	/* meta */
	$smarty->assign('keywords',           htmlspecialchars($goods['keywords']));
	$smarty->assign('description',        htmlspecialchars($goods['goods_brief']));

	//red add
	$red_sort = get_parent_cats($goods['cat_id'],$db);
	$smarty->assign('red_sort',            $red_sort[0]);                   // 类型

	$sql = "select a.cat_id,a.cat_name from `info_goods_cat` as gc left join `info_category` as a on a.cat_id=gc.cat_id where gc.goods_id='".$goods_id."' and gc.cat_id in ('67','68','69','70','71','72','73')";
	$red_ckc = $db->fetch_one($sql);
	$smarty->assign('red_ckc',            $red_ckc);                   // CKC分组

	//喜欢
	$sql = "select count(*) as num  from `info_goods_like` where goods_id='".$goods_id."'";
	$red_likeOne = $db->fetch_one($sql);
	$red_like = $red_likeOne['num'];
	if(empty($red_like)){
		$red_like = '0';
	}
	$smarty->assign('red_like',            $red_like);

	//Q+喜欢的人
	$sql = "select user_id from `info_goods_qlike` where goods_id='".$goods_id."' order by dateline desc limit 10";
	$red_like_user = $db->fetch_all($sql);
	$like_user = array();
	if(!empty($red_like_user)){
		foreach($red_like_user as $key=>$val){
			if(!empty($val['user_id'])){
				$like_user[] = get_qquser_info($val['user_id'],$db);
			}
		}
	}
	//大全喜欢的人	`info_goods_like`
	//$like_user[] = get_user_info($val['user_id'],$db);
	$smarty->assign('like_user',            $like_user);

	//添加的宠物
	$sql = "select `id`,`pic`,`name` from `info_user_pet` where `goods_id`='".$goods_id."' order by dateline desc limit 12 ";
	$user_pet = $db->fetch_all($sql);
	$smarty->assign('user_pet',            $user_pet);

	//判断宠物类型
	/*
	$array_dog = array('64','65','66');
	$array_cat = array('3');
	$array_sz = array('115','116','117','118','119','120','121','122','123','124','125','126');
	if(in_array($goods['cat_id'],$array_cat)){
		$pet_sort = 'cat';
	}elseif(in_array($goods['cat_id'],$array_sz)){
		$pet_sort = 'sz';
	}elseif(in_array($goods['cat_id'],$array_dog)){
		$pet_sort = 'dog';
	}*/
}
$smarty->assign('nav','daquan');
fheader();
$smarty->display('goods.dwt');
ffooter();